<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="/css/font-awesome-4.7.0/css/font-awesome.min.css" type="text/css">
  <link rel="stylesheet" href="https://static.pingendo.com/bootstrap/bootstrap-4.1.3.css">
  <title>SEHP资源共享平台</title>
</head>

<body>
  <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
    <div class="container"> <a class="navbar-brand" href="index.html">
        <i class="fa d-inline fa-lg fa-circle-o"></i>
        <b>SEHP资源共享平台</b>
      </a> <button class="navbar-toggler navbar-toggler-right border-0" type="button" data-toggle="collapse" data-target="#navbar11">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbar11">
        <ul class="navbar-nav mr-auto">
          <li class="nav-item"> <a class="nav-link" href="public.sehp">公共资源</a> </li>
          <li class="nav-item"> <a class="nav-link" href="private.sehp">我的资源</a> </li>
        </ul>
        <ul class="navbar-nav ml-auto" id="mynavbar">
          <li class="nav-item"> <a class="nav-link" href="myupload.sehp">我的上传</a> </li>
          <li class="nav-item"> <a class="nav-link" href="info.sehp">我的信息</a> </li>
        </ul> <a class="btn btn-primary navbar-btn ml-md-2" onclick="javascript:$('#myModal').modal()">上传文件</a>
      </div>
    </div>
  </nav>
  <div class="py-5" style="background-image: url('https://static.pingendo.com/cover-stripes.svg'); background-position:left center; background-size: cover;">
    <div class="container">
      <div class="row">
        <div class="p-5 col-lg-6">
          <h1>SEHP资源共享平台</h1>
          <p class="mb-3">基于SEHP(超级拓展超文本预处理器)开发的集资源上传、资源下载、资源共享为一体的资源共享平台。 <a href="register.html"> 点此注册</a></p>
            <div class="form-group"> <input type="text" class="form-control" placeholder="请输入用户名" id="UserName" name="UserName"> </div>
            <div class="form-group"> <input type="password" class="form-control" placeholder="请输入密码" id="PassWord" name="PassWord">
              <small class="form-text text-muted text-right">
                <a href="javascript:alert('请联系管理员修改密码！')"> 忘记自己密码?</a>
              </small> </div> <button type="submit" class="btn btn-primary btn-block btn-lg" onclick="Login()">登录</button>
        </div>
      </div>
    </div>
  </div>
  <div class="py-3">
    <div class="container">
      <div class="row">
        <div class="col-lg-4 col-6 p-3"> <i class="d-block fa fa-circle-o fa-5x text-primary"></i> </div>
        <div class="col-lg-4 col-6 p-3">
          <p class="mb-0"> <a href="http://chplang.com" target="_blank">SEHP官方网站</a> </p>
          <p class="mb-0"> <a href="https://github.com/leeli73/" target="_blank">Git仓库:https://github.com/leeli73/</a> </p>
          <p class="mb-0"> <a href="http://chplang.com" target="_blank">作者:Lee</a> </p>
          <p class="mb-0"> <a href="#">QQ:925776327</a> </p>
          <p class="mb-0"> <a href="mailto:leeli@live.cn">Email:leeli@live.cn</a> </p>
        </div>
        <div class="col-md-4 p-3">
          <h5> <b>关于</b> </h5>
          <p class="mb-0">超级拓展超文本预处理器-Super Expansion Hypertext Preprocessor。可将主流编程语言，如C/C++,Java,Python,Go,JS,易语言...直接嵌入HTML,无需进行新语法的学习,直接上手编写网站后端。</p>
        </div>
      </div>
    </div>
  </div>
  <!-- 模态框 -->
  <div class="modal fade" id="myModal">
    <div class="modal-dialog">
      <div class="modal-content">
   
        <!-- 模态框头部 -->
        <div class="modal-header">
          <h4 class="modal-title">资源上传</h4>
          <button type="button" class="close" data-dismiss="modal">&times;</button>
        </div>
   
        <!-- 模态框主体 -->
        <div class="modal-body">
          <iframe id="upm" src="http://127.0.0.1:8199/upload/show" width="100%" scrolling="no" frameborder="no"></iframe>
        </div>
   
        <!-- 模态框底部 -->
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
        </div>
   
      </div>
    </div>
  </div>
  <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.slim.min.js"></script>
  <script src="https://cdn.bootcss.com/popper.js/1.14.6/popper.js"></script>
  <script src="js/bootstrap.min.js"></script>
  <script>
    ShowWelcome()
    function Login()
    {
      if(getCookie("Keyt")!=null)
      {
        alert("您已经登录，请勿重复登录!");
        return ;
      }
      var UserName = document.getElementById("UserName").value
      var PassWord = document.getElementById("PassWord").value
      if(UserName == "" || PassWord == "")
      {
        alert("请输入用户名和密码！")
        return
      }
		  var xmlhttp=new XMLHttpRequest();
			  xmlhttp.onreadystatechange=function()
			  {
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
          {
            var Result = trimStr(xmlhttp.responseText)
            alert(Result);
            if(Result=="登录成功")
            {
              SetKeyt()
              window.location.href="index.html";
            }
          }
			  }
		  var data = "UserName="+UserName+"&PassWord="+PassWord;
		  xmlhttp.open("POST","lib/Login.sehp",true);
		  xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		  xmlhttp.send(data);
    }
    function trimStr(str){
      return str.replace(/(^\s*)|(\s*$)/g,"");
    }
    function setCookie(name,value) 
    { 
      var Days = 30; 
      var exp = new Date(); 
      exp.setTime(exp.getTime() + Days*24*60*60*1000); 
      document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); 
    } 
    function getCookie(name) 
    { 
        var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
        if(arr=document.cookie.match(reg))
            return unescape(arr[2]); 
        else 
            return null; 
    }
    function delCookie(key) {
        var date = new Date();
        date.setTime(date.getTime() - 1);
        var delValue = getCookie(key);
        if (!!delValue) {
            document.cookie = key+'='+delValue+';expires='+date.toGMTString();
        }
    }
    function ShowWelcome()
    {
      if(getCookie("UserName") != null)
      {
        var elem_li = document.createElement('li'); // 生成一个 li元素
        elem_li.innerHTML = '<li class="nav-item"> <a class="nav-link" href="javascript:delCookie(\'UserName\');delCookie(\'Keyt\');window.location.href=\'index.html\';" id="Welcome">欢迎您,'+getCookie("UserName")+'</a> </li>'
        document.getElementById("mynavbar").appendChild(elem_li)
        var ifr = document.getElementById("upm");
        ifr.src="http://127.0.0.1:8199/upload/show?UserName="+getCookie("UserName");
        console.log(ifr.src)
      }
    }
    function SetKeyt()
    {
      var UserName = document.getElementById("UserName").value
      setCookie("UserName",UserName)
      var xmlhttp=new XMLHttpRequest();
      xmlhttp.onreadystatechange=function()
        {
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
              var Result = trimStr(xmlhttp.responseText)
              setCookie("Keyt",Result)
              ShowWelcome()
            }
        }
      var data = "UserName="+UserName;
      xmlhttp.open("POST","lib/GetKeyt.sehp",true);
      xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
      xmlhttp.send(data);
    }
  </script>
</body>

</html>